
Public Class Prename

    Protected _prename_id As Integer
    Protected _prename_short_tha As String
    Protected _prename_short_eng As String
    Protected _prename_full_tha As String
    Protected _prename_full_eng As String
    Protected _order_id As Integer
    Protected _Data As ArrayList
    Protected _DataCurrent As Integer

    Public Property prename_id() As Integer
        Get
            Return _prename_id
        End Get
        Set(ByVal value As Integer)
            _prename_id = value
        End Set
    End Property

    Public Property prename_short_tha() As String
        Get
            Return _prename_short_tha
        End Get
        Set(ByVal value As String)
            _prename_short_tha = value
        End Set
    End Property

    Public Property prename_short_eng() As String
        Get
            Return _prename_short_eng
        End Get
        Set(ByVal value As String)
            _prename_short_eng = value
        End Set
    End Property

    Public Property prename_full_tha() As String
        Get
            Return _prename_full_tha
        End Get
        Set(ByVal value As String)
            _prename_full_tha = value
        End Set
    End Property

    Public Property prename_full_eng() As String
        Get
            Return _prename_full_eng
        End Get
        Set(ByVal value As String)
            _prename_full_eng = value
        End Set
    End Property

    Public Property order_id() As Integer
        Get
            Return _order_id
        End Get
        Set(ByVal value As Integer)
            _order_id = value
        End Set
    End Property

    Public Function getPrename() As System.Data.DataSet
        Dim outResult As New System.Data.DataSet()
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_Prename"

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(outResult, "trprename")

        Return outResult
    End Function

    Protected Function getsPrename() As ArrayList
        Dim outResult As New ArrayList()
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_Prename"

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "tablePrename")

        For Each objDr As System.Data.DataRow In objDs.Tables("tablePrename").Rows
            Dim obj As Prename = New Prename
            obj.prename_id = objDr.Item("prename_id").ToString()
            obj.prename_short_tha = objDr.Item("prename_short_tha").ToString()
            obj.prename_short_eng = objDr.Item("prename_short_eng").ToString()
            obj.prename_full_tha = objDr.Item("prename_full_tha").ToString()
            obj.prename_full_eng = objDr.Item("prename_full_eng").ToString()
            obj.order_id = objDr.Item("order_id").ToString()
            outResult.Add(obj)
        Next

        Return outResult
    End Function

    Protected Function getsPrenameByShortNameThai(ByVal prename As String) As Integer
        Dim outResult As Integer = 0
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_PrenameByShortNameThai"

        Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inPrename", prename)
        objCmd.Parameters.Add(objParam)

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "tablePrename")

        For Each objDr As System.Data.DataRow In objDs.Tables("tablePrename").Rows
            outResult = CInt(objDr("prename_id").ToString())
        Next

        Return outResult
    End Function

    Public Function NextRecord() As Boolean
        If ((Not _Data Is Nothing) AndAlso (((Not _Data Is Nothing) AndAlso _
            (_DataCurrent < _Data.Count And _Data.Count > 0)))) Then
            _prename_id = _Data(_DataCurrent).prename_id
            _prename_short_tha = _Data(_DataCurrent).prename_short_tha
            _prename_short_eng = _Data(_DataCurrent).prename_short_eng
            _prename_full_tha = _Data(_DataCurrent).prename_full_tha
            _prename_full_eng = _Data(_DataCurrent).prename_full_eng
            _order_id = _Data(_DataCurrent).order_id

            _DataCurrent += 1
            Return True
        End If
        Return False
    End Function

    Public Sub LoadPrename()
        _Data = New ArrayList
        _DataCurrent = 0
        _Data = getsPrename()
    End Sub

    Public Function LoadPrenameByShortNameThai(prename As String) As Integer
        Return getsPrenameByShortNameThai(prename)
    End Function

    Public Function GetAllPrename() As DataTable
        Dim outResult As New System.Data.DataSet()
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_Prename"

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        objDa.Fill(outResult, "trprename")
        outResult.Tables(0).PrimaryKey = New DataColumn() {outResult.Tables(0).Columns("prename_id")}

        Return outResult.Tables(0)
    End Function

    Public Function GetPrenameByShortNameThai(ByVal prename As String, ByVal dtPrename As DataTable) As Integer
        Dim outResult As Integer = 0
        Dim findRow() As DataRow
        findRow = dtPrename.Select("prename_short_tha = '" & prename & "'")

        'Return IIf(UBound(findRow) = 0, 0, CType(findRow(0).Item("prename_id"), Integer))

        If UBound(findRow) < 0 Then
            outResult = 0
        Else
            outResult = CType(findRow(0).Item("prename_id"), Integer)
        End If

        Return outResult
    End Function

End Class
